#coding=utf-8

import requests,json
from pprint import pprint
from utils.jwter import JwtGenerator
#auth_str = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTM5LjIxOS4y' \
#           +'MzYuMzM6MjA4MC9hcGkvZmVlZC1tZXNzYWdlcy90b3V6aWppZ291ZG9uZ3hpYW5nLzAiLCJpYXQiOj' \
#            +'E0OTcyMzAyODEsImV4cCI6MTQ5Nzk1MTM0MSwibmJmIjoxNDk3OTQ0MTQxLCJqdGkiOiJ2eU1IOWg2S' \
#             +'3RuQXlqeWRvIiwic3ViIjo1fQ.hXrwZJkXGB5twCNhzuwKsCvGEoBs7Pq_H2TtUlxR6hc'
#auth_str = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTM5LjIxOS4y' \
#           +'MzYuMzM6MjA4MC9hcGkvZmVlZC1tZXNzYWdlcy90b3V6aWppZ291ZG9uZ3hpYW5nLzAiLCJpYXQiOj' \
#            +'E0OTcyMzAyODEsImV4cCI6MTQ5Nzk1MTM0MSwibmJmIjoxNDk3OTQ0MTQxLCJqdGkiOiJ2eU1IOWg2S' \
#             +'3RuQXlqeWRvIiwic3ViIjo1fQ.hXrwZJkXGB5twCNhzuwKsCvGEoBs7Pq_H2TtUlxR6h'
#auth_str = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTM5LjIxOS4yMzYuMzM6MjA4MC9hcGkvYXV0aG9yaXphdGlvbiIsImlhdCI6MTUwNDE2ODAxOSwiZXhwIjoxNTA0MTc1NTQyLCJuYmYiOjE1MDQxNjgzNDIsImp0aSI6IjF6OXFBcDA5WExCTDlyV0UiLCJzdWIiOjd9.i51OXXdfA_gsWmzDTR0qCGTxjyrCVjOC_AlDHhbPDaI"
auth_str = 'Bearer '+JwtGenerator(20,200).get()
key_name = 'Authorization'

#def unicode_repr(self):
#    return self.encode('utf-8')
#old_repr = unicode.__repr__
#unicode.__repr__ = unicode_repr


def test_wrapper(url,method='GET',json_=False):
    def inner_wrapper(func):
        def final_wrapper(**kwargs):
            print 'test_url:',url
            print 'payload'
            pprint(kwargs)
            if method in ['GET','get']:
                responce = requests.get(url, headers={key_name: auth_str}, params=kwargs)
            elif method in ['POST','post']:
                if json_:
                    responce = requests.post(url, headers={key_name: auth_str}, json=kwargs)
                else:
                    responce = requests.post(url, headers={key_name: auth_str}, data=kwargs)
            else:
                raise
            func()
            if responce.status_code>=400:
                print responce.status_code,responce.text
                return
            print responce.text
            data_obj = json.loads(responce.text)
            pprint(data_obj)
            return
        return final_wrapper
    return inner_wrapper



@test_wrapper('http://localhost:9987/api/s/submituserinfo','post')
def local_submit_userinfo(**kwargs):
    pass


@test_wrapper('http://localhost:9987/api/s/submitsubscribe','post')
def local_submit_subscribe(**kwargs):
    pass


@test_wrapper('http://localhost:9987/api/s/getsubscribeinfo')
def local_get_subscribe_info(**kwargs):
    pass

@test_wrapper('http://localhost:9987/api/s/my-topics/submit','post',True)
def local_topic_submit(**kwargs):
    pass

@test_wrapper('http://localhost:9987/api/s/getsubscribekeyword')
def local_get_subscribe_keyword(**kwargs):
    pass

@test_wrapper('http://localhost:9987/api/s/keywordsubscribe')
def local_subscribe_recommend_keywords(**kwargs):
    pass

@test_wrapper('http://localhost:9987/api/s/getsubscribe')
def local_get_subscribe(**kwargs):
    pass

@test_wrapper('http://localhost:9987/api/s/my-topics')
def local_get_my_topic(**kwargs):
    pass


@test_wrapper('http://139.219.236.33:2080/api/subscribe/getsubscribe')
def ol_get_subscribe(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/getsubscribeinfo')
def ol_get_subscribe_info(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/getsubscribekeyword')
def ol_get_subscribe_keyword(**kwargs):
    pass


@test_wrapper('http://139.219.236.33:2080/api/subscribe/keywordsubscribe')
def ol_subscribe_recommend_keywords(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/submituserinfo','post')
def ol_submit_userinfo(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/submitsubscribe','post')
def ol_submit_subscribe(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/search')
def ol_search(**kwargs):
    pass
@test_wrapper('http://139.219.236.33:2080/api/subscribe/topic')
def ol_topic(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/my-topics')
def ol_get_my_topic(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/my-topics/customization')
def ol_get_my_topic_customization(**kwargs):
    pass

@test_wrapper('http://139.219.236.33:2080/api/subscribe/my-info')
def ol_get_my_info(**kwargs):
    pass
if __name__=='__main__':
    ol_get_my_info()
    #cell_phone = request.get_argument('cell_phone').encode('utf-8')
    #local_submit_userinfo(user=7,name='7号用户',corporation='随便个公司',occupation='不专业',email='jksada@mc.lom')
    #ol_get_subscribe(user=7,page=1)
    #local_get_subscribe_info(user=7)
    #ol_get_subscribe(user=5)
    #ol_get_subscribe_info(user=5)
    #local_get_subscribe_keyword(user=5)
    #ol_get_subscribe_keyword(user=5)
    #ol_get_subscribe(user=7,category_id=4,page=1)
    #local_submit_subscribe(user=5, keywords=json.dumps([['潘长江','长江','江']]), keyword_ids=json.dumps([1024,1042,1174]))
    #local_get_subscribe_info(user=5)
    #ol_get_subscribe_info(user=8)
    #local_subscribe_recommend_keywords(keyword='互联网')
    #ol_subscribe_recommend_keywords(keyword='安全')
    # 提交 李晓
    #ol_submit_userinfo(user=17,name='李骁',corporation='快签科技',occupation='CEO',email='jksada@mc.lom')
    # 提交 王烨
    #ol_submit_userinfo(user=16, name='王烨', corporation='六禾创投', occupation='总经理', email='jksada@mc.lom')
    # 杜挺 39973
    # 贾跃亭 8109
    # 魏志成 20674
    # 杨天桓 20263
    # 高斯蒙 39945
    # 万达集团 26137
    # 六禾创投 25078
    # 真格基金 24858
    # IDG资本 24751
    # 朋友印象 28369
    # 快签 35398
    # DEMO++ 39955
    # 数尊科技 39960
    # JoinQuant 38771
    # 第一海外金融 39952
    # 娱乐 42275
    # 区块链 42276
    # 人工智能 42274
    # 网络安全 42273
    #submit_list = [39973,8109,20674,20263,39945,26137,25078,24858,24751,24751,28369,35398,39955,39960,38771,39952,42275,42276,42274,42273]
    #ol_submit_subscribe(user=7,keyword_ids=json.dumps([42310]),keywords=json.dumps([]))
    #ol_submit_subscribe(user=16, keyword_ids=json.dumps(submit_list),keywords=json.dumps([]))
    #ol_search(keywords='红烧牛肉面',search_for='post,custom_post_basics',page=2)


